#!/bin/bash

export PROGRAM_NAME=bin/samebatch-multiproduct-binpacking-mpi

# script pouvant etre executer depuis le repertoire parent par 
# la commande script/runmpi
# ou depuis le repertoire src (travail avec emacs)
if [ ! -d "bin" ]; then
    echo moving to parent directory
    cd ..
fi

export DEFAULT_CMD_LINE=$1 $2 $3 $4 $5 $6
if [ $# = 0 ]; then
    export DEFAULT_CMD_LINE="-bbp data/instance037c1.txt "
fi 

# Interval of the search tree to dispatch the work to the slaves
# If the task are too small, the time to communicate will be very high
# if the task are too important, some nodes could starve and will have nothing to do.
# 
# As the search is done from the last job n back to the first one, these values should
# be rather close than 100% than 0% in order to to schedule few big tasks rather than 
# a lot of small tasks. 
export MIN_PERCENT_FOR_DISPATCHING=60
export MAX_PERCENT_FOR_DISPATCHING=80
export PERIOD_MPI_TEST_MASTER=1
export PERIOD_MPI_TEST_SLAVE=1

export DEFAULT_CMD_LINE=${DEFAULT_CMD_LINE}" -periodMPITestMaster ${PERIOD_MPI_TEST_MASTER} -periodMPITestSlave ${PERIOD_MPI_TEST_SLAVE} -minPercentForDispatching ${MIN_PERCENT_FOR_DISPATCHING} -maxPercentForDispatching ${MAX_PERCENT_FOR_DISPATCHING}"

#mpirun --hostfile bhost -np 2 bin/samebatch-muliproduct-binpacking-mpi $1 $2 $3 $4 $5 $6

echo time mpirun -np 4 ${PROGRAM_NAME} ${DEFAULT_CMD_LINE}

time mpirun -np 4 ${PROGRAM_NAME} ${DEFAULT_CMD_LINE}

